package com.vcms.controller.system;

import com.vcms.controller.customer.TransactionController;
import com.vcms.controller.machine.MachinaryController;
import com.vcms.controller.maintenance.MaintenanceController;
import com.vcms.controller.storemanagement.StoreController;
import com.vcms.exception.VMCSException;
import com.vcms.utility.Environment;
import com.vcms.view.simulation.system.SimulatorControlPanel;

/**
 * @author Team 7 PT
 * @version 1.0
 */

public class MainController {
	private SimulationController simulatorCtrl;
	private MaintenanceController maintenanceCtrl;
	private MachinaryController machinaryController;
	private StoreController storeCtrl;
	private TransactionController transactionController;

	public Environment env;

	public MainController() {
	}

	public void initialize() throws VMCSException {
		try {
			env = new Environment();
			env.initialize();
			
			storeCtrl = new StoreController(this);
			storeCtrl.initialize();
			
			simulatorCtrl = new SimulationController(this);
			machinaryController = new MachinaryController(this);
			machinaryController.initialize();
			
			maintenanceCtrl = new MaintenanceController(this);
			transactionController = new TransactionController(this);
			
		} catch (VMCSException e) {
			throw new VMCSException("MainController.initialize", e.getMessage());
		}
	}

	public void start() throws VMCSException {
		try {
			initialize();
			simulatorCtrl.displaySimulatorControlPanel();
			simulatorCtrl.setSimulationActive(false);
		} catch (VMCSException e) {
			throw new VMCSException(e);
		}
	}

	public SimulationController getSimulationController() {return simulatorCtrl;}
	public SimulatorControlPanel getSimulatorControlPanel() {return simulatorCtrl.getSimulatorControlPanel();}
	public StoreController getStoreController() {return storeCtrl;}
	public MaintenanceController getMaintenanceController() {return maintenanceCtrl;}
	public TransactionController getTransactionController() {return this.transactionController;}
	public MachinaryController getMachinaryController() {return machinaryController;}

	public void closeDown() {

		if (maintenanceCtrl.closeDown() == false)
			return;
		try {
			storeCtrl.closeDown();
		} catch (VMCSException e) {
			System.out.println("MainController.closeDown" + e);
		}
		transactionController.closeDown();
		machinaryController.closeDown();
		simulatorCtrl.closeDown();
	}
}
